package com.ox.head.okex.config;



import com.ox.head.okex.common.OkHeader;
import com.ox.head.okex.common.sign.OkSignUtil;
import com.ox.head.okex.properties.OkProperties;
import com.ox.head.okex.service.OkSpotApiClient;
import com.ox.head.okex.service.impl.OkSpotApiClientImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.util.UriBuilder;


/**
 * @author even
 * @date 2021/5/14 0014 下午 12:07
 * @describe
 * 配置文件
 */
@Configuration
@EnableConfigurationProperties(value = OkProperties.class)
@ConditionalOnProperty(prefix = OkProperties.PREFIX, name = "enable", havingValue = "true")
public class OkAutoConfiguration {


    @Bean("okWebClient")
    @ConditionalOnMissingBean
    public WebClient okWebClient(OkProperties okProperties){
        return WebClient.builder()
                .defaultHeader(OkHeader.HEADER_TYPE, MediaType.APPLICATION_JSON_VALUE)
                .defaultHeader(OkHeader.HEADER_ACCESS_KEY,okProperties.getAccessKeyId())
                .defaultHeader(OkHeader.HEADER_ACCESS_PASSPHRASE,okProperties.getPassphrase())
                .baseUrl(okProperties.getUrl())
                .build();
    }

    @Bean("okSpotApiClient")
   public OkSpotApiClient okSpotApiClient(WebClient okWebClient, OkProperties okProperties){
        return new OkSpotApiClientImpl(okWebClient,okProperties);
   }
}
